package com.tl.web03.utils;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 获取json参数工具类
 */
public class JsonParamUtil {
    public static JSONObject getJsonParam(HttpServletRequest req) throws IOException {
        //获取json参数
        BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream(), "utf-8"));
        StringBuilder stringBuilder = new StringBuilder();
        String temp = "";
        while((temp= br.readLine())!=null){
            stringBuilder.append(temp);
        }
        br.close();
        String param = stringBuilder.toString();
        return  JSONObject.parseObject(param);
    }
}
